package dataMapper;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import dataEntity.SummaryMeasuresOfHealth;

public class SummaryMeasuresOfHealthMapper {
	public static  Map<String,Map<String,SummaryMeasuresOfHealth>> process(BufferedReader br){
		Map<String,Map<String,SummaryMeasuresOfHealth>> map = new HashMap<String,Map<String,SummaryMeasuresOfHealth>> ();
		try {
			br.readLine();
			while(br.ready()){
				SummaryMeasuresOfHealth object = buildObject(br.readLine());

				Map<String,SummaryMeasuresOfHealth> stateMap = map.get(object.getCHSI_State_Abbr());
				if(stateMap == null) stateMap = new HashMap<String,SummaryMeasuresOfHealth>();
				stateMap.put(object.getCHSI_County_Name(), object);
				map.put(object.getCHSI_State_Abbr(), stateMap);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map;
	}
	
	public static  SummaryMeasuresOfHealth buildObject(String inLine){
		String[] line = inLine.split(",");
		SummaryMeasuresOfHealth object = new SummaryMeasuresOfHealth();
		
		object.setState_FIPS_Code(line[0]);
		object.setCounty_FIPS_Code(line[1]);
		object.setCHSI_County_Name(line[2]);
		object.setCHSI_State_Name(line[3]);
		object.setCHSI_State_Abbr(line[4]);
		object.setStrata_ID_Number(line[5]);
		object.setALE(line[6]);
		object.setMin_ALE(line[7]);
		object.setMax_ALE(line[8]);
		object.setUS_ALE(line[9]);
		object.setAll_Death(line[10]);
		object.setMin_All_Death(line[11]);
		object.setMax_All_Death(line[12]);
		object.setUS_All_Death(line[13]);
		object.setCI_Min_All_Death(line[14]);
		object.setCI_Max_All_Death(line[15]);
		object.setHealth_Status(line[16]);
		object.setMin_Health_Status(line[17]);
		object.setMax_Health_Status(line[18]);
		object.setUS_Health_Status(line[19]);
		object.setCI_Min_Health_Status(line[20]);
		object.setCI_Max_Health_Status(line[21]);
		object.setUnhealthy_Days(line[22]);
		object.setMin_Unhealthy_Days(line[23]);
		object.setMax_Unhealthy_Days(line[24]);
		object.setUS_Unhealthy_Days(line[25]);
		object.setCI_Min_Unhealthy_Days(line[26]);
		object.setCI_Max_Unhealthy_Days(line[27]);

		return object;
	}
}
